package noodlesscm;

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.util.*;
import javax.swing.table.DefaultTableModel;

class ProductInventory {
public void displayInventory()
	{
	Vector vi=new Vector();
	Product p=new Product();
	Inventory inven;
	int code=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter the product unique id"));
	Object[] col = new Object[]{"Name","InventoryId","Quantity","Price"};
	Object[][] data = {};
	DefaultTableModel model = new DefaultTableModel(data,col);
	JTable table = new JTable(model);


	try {

              XMLDecoder istream = new XMLDecoder(new BufferedInputStream(new FileInputStream("d:/Netbeans/noodlesscm/products.xml")));
              ProductList pobj =(ProductList) istream.readObject();
                istream.close();

	p=new Product();




	for(int i=0;i<pobj.products.size();i++)
	{
	p=(Product) pobj.products.get(i);
	if(p.getProductid()==code)
	{
	vi=p.getInvenlist1();
	break;
	}
	}

	}
	catch(Exception ex) {
         System.out.println(ex);
      	}


	try {

               XMLDecoder istream = new XMLDecoder(new BufferedInputStream(new FileInputStream("d:/Netbeans/noodlesscm/inventory.xml")));
               InventoryList iobj =(InventoryList) istream.readObject();
                istream.close();



	for(int i=0;i<iobj.inventories.size();i++)
	{
	inven=(Inventory) iobj.inventories.get(i);
	for(int j=0;j<vi.size();j++)
	{
	if(inven.getName().equals(vi.get(j)))
	{
	Object[] row1=new Object[]{inven.getName(),inven.getInventoryid(),inven.getQuantity(),inven.getPrice()};
	model.addRow(row1);
	}
	}
	}
	JScrollPane pane = new JScrollPane( table );
	JFrame jfr=new JFrame("List of Inventory for product "+p.getName());
	jfr.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	jfr.setBackground(Color.white);
	jfr.setSize(600,300);
        jfr.setVisible(true);
	jfr.setLocation(200,200);
	jfr.add(pane);
	}


		catch(Exception ex) {
         	System.out.println(ex);
      		}
}
}
